//
//  RegisterViewController.m
//  MyProject
//
//  Created by dllo on 15/11/1.
//  Copyright (c) 2015年 蓝鸥0825. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()

@property(nonatomic, retain)UITextField *textRegisterPass;
@property(nonatomic, retain)UITextField *textRepeatPass;
@property(nonatomic, assign)BOOL isSelected;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //      用户名
    UILabel *labelRegisterUser = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, 150, 40)];
    labelRegisterUser.backgroundColor = [UIColor clearColor];
    [self.view addSubview:labelRegisterUser];
    [labelRegisterUser release];
    labelRegisterUser.text = @"用户名 :";
    labelRegisterUser.textAlignment = NSTextAlignmentCenter;
    labelRegisterUser.font = [UIFont systemFontOfSize:25];
    
    
    
    //      填写用户名
    self.textRegisterUser = [[UITextField alloc] initWithFrame:CGRectMake(150, 150, 200, 40)];
    self.textRegisterUser.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.textRegisterUser];
    [self.textRegisterUser release];
    self.textRegisterUser.layer.borderWidth = 1;
    self.textRegisterUser.layer.cornerRadius = 10;
    self.textRegisterUser.layer.masksToBounds = YES;
    
    self.textRegisterUser.placeholder = @"请输入用户名";
    self.textRegisterUser.textAlignment = NSTextAlignmentCenter;
    self.textRegisterUser.font = [UIFont systemFontOfSize:25];
    
    
    
    //      密码
    UILabel *labelRegisterPass = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, 150, 40)];
    labelRegisterPass.backgroundColor = [UIColor clearColor];
    [self.view addSubview:labelRegisterPass];
    [labelRegisterPass release];
    labelRegisterPass.text = @"密码 :";
    labelRegisterPass.textAlignment = NSTextAlignmentCenter;
    labelRegisterPass.font = [UIFont systemFontOfSize:25];
    
    
    
    //      填写密码
    self.textRegisterPass = [[UITextField alloc] initWithFrame:CGRectMake(150, 200, 200, 40)];
    self.textRegisterPass.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.textRegisterPass];
    [self.textRegisterPass release];
    self.textRegisterPass.layer.borderWidth = 1;
    self.textRegisterPass.layer.cornerRadius = 10;
    self.textRegisterPass.layer.masksToBounds = YES;
    self.textRegisterPass.clearButtonMode = UITextFieldViewModeAlways;
    
    self.textRegisterPass.placeholder = @"请输入密码";
    self.textRegisterPass.textAlignment = NSTextAlignmentCenter;
    self.textRegisterPass.font = [UIFont systemFontOfSize:25];
    
    //      密码
    UILabel *labelRepeatPass = [[UILabel alloc] initWithFrame:CGRectMake(0, 250, 150, 40)];
    labelRepeatPass.backgroundColor = [UIColor clearColor];
    [self.view addSubview:labelRepeatPass];
    [labelRepeatPass release];
    labelRepeatPass.text = @"确认密码 :";
    labelRepeatPass.textAlignment = NSTextAlignmentCenter;
    labelRepeatPass.font = [UIFont systemFontOfSize:25];
    
    
    
    //      填写密码
    self.textRepeatPass = [[UITextField alloc] initWithFrame:CGRectMake(150, 250, 200, 40)];
    self.textRepeatPass.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.textRepeatPass];
    [self.textRepeatPass release];
    self.textRepeatPass.layer.borderWidth = 1;
    self.textRepeatPass.layer.cornerRadius = 10;
    self.textRepeatPass.layer.masksToBounds = YES;
    self.textRepeatPass.clearButtonMode = UITextFieldViewModeAlways;
    
    self.textRepeatPass.placeholder = @"请再次输入密码";
    self.textRepeatPass.textAlignment = NSTextAlignmentCenter;
    self.textRepeatPass.font = [UIFont systemFontOfSize:25];
    [self.textRepeatPass addTarget:self action:@selector(value :) forControlEvents:UIControlEventEditingChanged];
    
    //      注册密码是否相同
    UILabel *labelPass = [[UILabel alloc] initWithFrame:CGRectMake(150, 300, 200, 40)];
    labelPass.layer.borderWidth = 1;
    labelPass.layer.cornerRadius = 10;
    [self.view addSubview:labelPass];
    [labelPass release];
    labelPass.tag = 1000;
    
    
    //      注册按钮
    UIButton *buttonSubmit = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonSubmit.frame = CGRectMake(225, 400, 100, 40);
    buttonSubmit.backgroundColor = [UIColor clearColor];
    [self.view addSubview:buttonSubmit];
    
    buttonSubmit.layer.borderWidth = 1;
    buttonSubmit.layer.cornerRadius = 10;
    [buttonSubmit setTitle:@"提交" forState:UIControlStateNormal];
    buttonSubmit.titleLabel.font = [UIFont systemFontOfSize:25];
    
    
    [buttonSubmit addTarget:self action:@selector(clickSubmit:) forControlEvents:UIControlEventTouchUpInside];
    
    
}

//      提交按钮
- (void)clickSubmit : (UIButton *)button {
    
    UILabel *label = (UILabel *)[self.view viewWithTag:1000];
    if ([label.text  isEqualToString: @"相同"]) {
        UIAlertView *alertRegistrView = [[UIAlertView alloc] initWithTitle:@"注册成功" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        [alertRegistrView show];
//        [self.view bringSubviewToFront:self.viewLogin];
        
    } else {
        
        UIAlertView *alertRegistrView = [[UIAlertView alloc] initWithTitle:@"注册失败" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        [alertRegistrView show];
        
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}




//      注册密码是否相同
- (void)value : (UITextField *)textField {
    UILabel *label = (UILabel *)[self.view viewWithTag:1000];
    
    if ([self.textRegisterPass.text isEqualToString:self.textRepeatPass.text]) {
        label.text = @"相同";
    } else {
        label.text = @"不相同";
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
